package learning.groovy.closure

class ClosureDemo {
	
	static Map map = ['a':1, 'b':2]
	
	static main(args){
		map.each{ key, value -> map[key] = value * 2 }
		println map
		//[a:2, b:4]
		
		Closure doubler = { key, value -> map[key] = value * 2 }
		map.each(doubler)
		println map
		//[a:4, b:8]
		
		doubler = this.&doubleMethod
		map.each(doubler)
		println map
		//[a:8, b:16]
		
	}
	
	static def doubleMethod (entry){
		map[entry.key] = entry.value * 2
	}
	
}
